package com.cleaningcloud.cld.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.cleaningcloud.cld.domain.CldProjectPost;
import com.cleaningcloud.cld.domain.dto.CldComplaintsDto;
import com.cleaningcloud.cld.domain.dto.CldProjectPostDto;
import com.cleaningcloud.cld.domain.vo.CldComplaintsReplyVo;
import com.cleaningcloud.cld.domain.vo.CldComplaintsVo;
import com.cleaningcloud.cld.domain.vo.CldProjectPostSetVo;
import com.cleaningcloud.cld.mapper.CldProjectPostMapper;
import com.cleaningcloud.common.core.utils.DateUtils;
import com.cleaningcloud.common.security.utils.DictUtils;
import com.cleaningcloud.common.security.utils.SecurityUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cleaningcloud.cld.mapper.CldComplaintsMapper;
import com.cleaningcloud.cld.domain.CldComplaints;
import com.cleaningcloud.cld.service.ICldComplaintsService;

/**
 * 客诉与处置Service业务层处理
 * 
 * @author cleaningcloud
 * @date 2024-10-17
 */
@Service
public class CldComplaintsServiceImpl implements ICldComplaintsService 
{
    @Autowired
    private CldComplaintsMapper cldComplaintsMapper;

    @Autowired
    private CldProjectPostMapper projectPostMapper;

    /**
     * 查询客诉与处置
     * 
     * @param complaintsId 客诉与处置主键
     * @return 客诉与处置
     */
    @Override
    public CldComplaintsVo selectCldComplaintsByComplaintsId(Long complaintsId)
    {
        // 查询项目岗位字典
        Map<String, String> projectPostMap = DictUtils.getDictDataMap("cld_project_post");
        CldComplaintsVo cldComplaintsVo = cldComplaintsMapper.selectCldComplaintsByComplaintsId(complaintsId);
        for (CldComplaintsReplyVo cldComplaintsReplyVo : cldComplaintsVo.getReplyList()) {
            cldComplaintsReplyVo.setReplyStaffPostName(projectPostMap.get(cldComplaintsReplyVo.getReplyStaffPostName()));
        }
        return cldComplaintsVo;
    }

    /**
     * 查询客诉与处置列表
     * 
     * @param cldComplaints 客诉与处置
     * @return 客诉与处置
     */
    @Override
    public List<CldComplaintsVo> selectCldComplaintsList(CldComplaintsDto cldComplaints)
    {
        return cldComplaintsMapper.selectCldComplaintsList(cldComplaints);
    }

    @Override
    public List<CldComplaintsVo> selectCldComplaintsGroupProjectList(CldComplaintsDto cldComplaintsDto) {
        return cldComplaintsMapper.selectCldComplaintsGroupProjectList(cldComplaintsDto);
    }

    /**
     * 新增客诉与处置
     * 
     * @param cldComplaints 客诉与处置
     * @return 结果
     */
    @Override
    public int insertCldComplaints(CldComplaints cldComplaints)
    {
        cldComplaints.setComplaintTime(DateUtils.getNowDate());
        cldComplaints.setProjectAccountId(SecurityUtils.getUserId());
        cldComplaints.setHandleStatus(0L);
        return cldComplaintsMapper.insertCldComplaints(cldComplaints);
    }

    /**
     * 修改客诉与处置
     * 
     * @param cldComplaints 客诉与处置
     * @return 结果
     */
    @Override
    public int updateCldComplaints(CldComplaints cldComplaints)
    {
        return cldComplaintsMapper.updateCldComplaints(cldComplaints);
    }



    /**
     * 批量删除客诉与处置
     * 
     * @param complaintsIds 需要删除的客诉与处置主键
     * @return 结果
     */
    @Override
    public int deleteCldComplaintsByComplaintsIds(Long[] complaintsIds)
    {
        return cldComplaintsMapper.deleteCldComplaintsByComplaintsIds(complaintsIds);
    }

    /**
     * 删除客诉与处置信息
     * 
     * @param complaintsId 客诉与处置主键
     * @return 结果
     */
    @Override
    public int deleteCldComplaintsByComplaintsId(Long complaintsId)
    {
        return cldComplaintsMapper.deleteCldComplaintsByComplaintsId(complaintsId);
    }
}
